//
//  Cos.cpp
//  Lab12-calcul functie
//
//  Created by Cristi Holdunu on 5/22/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include "Sin.h"
#include "Cos.h"
#include "Produs.h"
#include <iostream>
#include <math.h>
long double Cos::calcul(long double aux1)
{
    return (cos(aux1));
}

long double Cos::calcul()
{
    if(!fStang)
        exit(1);
    return calcul(fStang->calcul());
}
std::string Cos::derivare()
{
    std::string aux, aux1, aux2,aux00;
    if (!fStang)
        exit(1);
    aux1=fStang->derivare();
    aux2=fStang->convertString();
    aux00=Sin::concatTermeni(aux2);
    aux=Produs::concatTermeni(aux00, aux1);
    return aux;
}
long double Cos::calculDerivata()
{
    if(!fStang)
        exit(1);
    return Produs::calcul(Sin::calcul(fStang->calcul()),fStang->calculDerivata());
}
std::string Cos::convertString()
{
    std::string aux, aux1;
    int nrP;
    if(!fStang)
        exit(1);
    aux=fStang->convertString();
    aux=concatTermeni(aux1);
    return aux;
}

std::string Cos::concatTermeni(std::string aux1)
{
    std::string aux;
    int nrP;
    nrP=aux1[0]=='('? 0 :2;
    aux="Cos";
    if(nrP) 
        aux=aux+"(";
    aux=aux+aux1;
    if (nrP)
        aux=aux+")";
    return aux;
}